package com.jixiantubu.adapter;

import image.SmartImageView;
import java.util.ArrayList;
import java.util.List;
import com.example.jixiantubu.R;
import com.jixiantubu.bean.Ac_Bean;
import com.jixiantubu.util.MyApplication;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Wo_faqihuodongadapter extends BaseAdapter {

	// 通过构造器获取数据来源
		List<Ac_Bean> list = new ArrayList<Ac_Bean>();
		// 接收上下文参数，以便了解是哪个activity在调用
		Context context;
		// 用来初始化布局文件，可以把一个xml布局转换为对应的android对象view
		LayoutInflater mInflater;
		ViewHolder mHolder;
		
	public Wo_faqihuodongadapter(List<Ac_Bean> list, Context context) {
			super();
			this.list = list;
			this.context = context;
			mInflater = LayoutInflater.from(context);
		}

	
	public List<Ac_Bean> getList() {
		return list;
	}


	public void setList(List<Ac_Bean> list) {
		this.list = list;
	}


	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override			//	position   convertView    parent
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// 告知列表每一行的布局样式，同时指定每一行的数据来自哪里
		// position:列表的索引，从0开始；convertView是每一行的布局；parent每一行的父布局，没有则写null
		// 这里，每一行的布局是item.xml
		mHolder = new ViewHolder();
		if (arg1 == null) {
			arg1 = mInflater.inflate(R.layout.wo_jieban_faqi_detail, null);
			// 初始化每一行的控件
			
			mHolder.wo_jieban_tupian = (SmartImageView) arg1
					.findViewById(R.id.wo_jieban_tupian);
		
			mHolder.wo_jieban_renshu = (TextView) arg1
					.findViewById(R.id.wo_jieban_renshu);
			mHolder.wo_jieban_biaoti = (TextView) arg1
					.findViewById(R.id.wo_jieban_biaoti);
			mHolder.wo_jieban_jihedi = (TextView) arg1
					.findViewById(R.id.wo_jieban_jihedi);
			mHolder.wo_jieban_kaishijieshushijian = (TextView) arg1.findViewById(R.id.wo_jieban_kaishijieshushijian);
			mHolder.wo_jieban_zuzhizhe = (TextView) arg1
					.findViewById(R.id.wo_jieban_zuzhizhe);
			// 首次调用getView，创建viewHolder实例，初始化控件，并把这个实例缓存到界面上
			arg1.setTag(mHolder);
		} else {
			// 不是第一次调用，直接取出缓存中的viewholder即可
			mHolder = (ViewHolder) arg1.getTag();
		}

		// 指定每一行布局对应的数据
		String resId = "http://" + MyApplication.getIP() + ":8080/Jinnang/img/"
				+ list.get(arg0).getAc_pic_path();
		Log.e("约伴图片11111111", resId);
		
		mHolder.wo_jieban_tupian.setImageUrl(resId);
		int wo_jieban_renshu = +list.get(arg0).getAc_number_sum();
		String wo_jieban_biaoti = list.get(arg0).getAc_title();
		String wo_jieban_jihedi = list.get(arg0).getAc_venue();
		String wo_jieban_kaishijieshushijian = list.get(arg0).getAc_time().substring(0,10) + "—"
				+ list.get(arg0).getAc_lastTime().substring(0,10);
		String wo_jieban_zuzhizhe = list.get(arg0).getUser_nickname();
		mHolder.wo_jieban_renshu.setText("已报名"+String.valueOf(wo_jieban_renshu)+"人");
		mHolder.wo_jieban_biaoti.setText(wo_jieban_biaoti);
		mHolder.wo_jieban_jihedi.setText("集合地："+wo_jieban_jihedi);
		mHolder.wo_jieban_kaishijieshushijian.setText("时间："+wo_jieban_kaishijieshushijian);
		mHolder.wo_jieban_zuzhizhe.setText("组织者："+wo_jieban_zuzhizhe);

		return arg1;
	}

	class ViewHolder {
		// 做界面控件初始化缓存工作
		SmartImageView wo_jieban_tupian;
		TextView wo_jieban_renshu, wo_jieban_biaoti, wo_jieban_jihedi, wo_jieban_kaishijieshushijian, wo_jieban_zuzhizhe;

	}

}
